package com.haoshuang.zhouzhoubang.ui.page.account.login

import com.haoshuang.zhouzhoubang.base.BaseCommonViewModel
import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.UserBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class LoginViewModel : BaseCommonViewModel() {

    /**
     * 微信登录
     */
    val wechatLoginData = StatefulMutableLiveData<ResponseBean<UserBean>>()
    fun wechatLogin(code: String) = netRequest {
        start { wechatLoginData.value = StateData.Loading }
        request { ApiRepo.wechatLogin(code)  }
        success { wechatLoginData.value = StateData.Success(it) }
        error { code, msg ->
            wechatLoginData.value = StateData.Error(code, msg)
        }
    }

}